package main

import "fmt"

func showAddr(x []int) []int {
	fmt.Printf("x %p, %p, l=%-2d, c=%-2d, %v\n", &x, &x[0], len(x), cap(x), x)
	if len(x) > 0 {
		x[0] = 100
	}
	x = append(x, 111)
	fmt.Printf("x %p, %p, l=%-2d, c=%-2d, %v\n", &x, &x[0], len(x), cap(x), x)
	return x
}

func main() {
	s1 := []int{10, 30, 50}
	fmt.Printf("s1 %p, %p, l=%-2d, c=%-2d, %v\n", &s1, &s1[0], len(s1), cap(s1), s1)

	s2 := s1 // 赋值
	fmt.Printf("s2 %p, %p, l=%-2d, c=%-2d, %v\n", &s2, &s2[0], len(s2), cap(s2), s2)

	s3 := showAddr(s1)
	fmt.Printf("s1 %p, %p, l=%-2d, c=%-2d, %v\n", &s1, &s1[0], len(s1), cap(s1), s1)
	fmt.Printf("s2 %p, %p, l=%-2d, c=%-2d, %v\n", &s2, &s2[0], len(s2), cap(s2), s2)
	fmt.Printf("s3 %p, %p, l=%-2d, c=%-2d, %v\n", &s3, &s3[0], len(s3), cap(s3), s3)
}
